package leasingcompany;


public class CarYeWu {

    Vechile cars[] = new Vechile[5];

    public void caBook(){
        System.out.println("--汽车信息如下--");
        for(int i=0;i<cars.length;i++) {
            if (cars[i] == null) {
                  break;
            }
            cars[i].show();
        }
    }
    //租车
    public Vechile lease(String id,int days,int leiX){
         for(int i=0;i<cars.length;i++){
             if(cars[i]==null){
                 break;
             }
             if(id.equals(cars[i].getId()) && cars[i].isState()==true){
                 cars[i].rent(days);
                 cars[i].setState(false);
                 System.out.println("租赁成功,祝您用车愉快！");
                 return cars[i];
             }else{
                continue;
             }
         }
        System.out.println("没有此车，或以被出租！");
        return null;
    }
    //还车
    public boolean huanCe(String id){
         for(int i=0;i<cars.length;i++){
             if(cars[i].getId().equals(id)&&!cars[i].isState()){
                cars[i].setState(true);
                 return true;
             }
         }
         return false;
    }
    //添加，车牌不能重复
    public boolean add(Vechile vech) {
        for(int i=0;i<cars.length;i++){
            if (cars[i] == null) {
                cars[i]=vech;
                return true;
            }
            if(cars[i].getId().equals(vech.getId())){
                return false;
            }
        }
        return false;
    }
    //报废
    public boolean carTool(String id){
        for(int i=0;i<cars.length;i++){
            if(cars[i].getId().equals(id)) {
                cars[i]=null;
                for (int j=i;j<cars.length-1;j++){
                    cars[j]=cars[j+1];
                }
                cars[cars.length-1]=null;
                //cars.length--;
                //stu[pos-1]=null;
                //pos--
                return true;
            }
        }
        return false;
    }
}
